﻿@model Models.Models.DomainList
@using WebApp.Classes

@{
    ViewBag.Title = "Domain Management";
}

@Scripts.Render("~/scripts/jquery.validate.js")
@Scripts.Render("~/scripts/jquery.validate.unobtrusive.js")
@Scripts.Render("~/scripts/partialViewValidation.js")

@Scripts.Render("~/scripts/app/EditDomainPartial.js")
@Scripts.Render("~/scripts/app/" + Path.GetFileNameWithoutExtension(Server.MapPath(VirtualPath)) + ".js")

    <fieldset>
        @Html.GetTitle("/Images/glyphicons/png/glyphicons_280_settings.png", new string[] { HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString() + "/" + ViewBag.Title })

        <div class="alert alert-info">
            Please select a domain to update or add a new one.
            <div style='float: right' id="divRevoked">            
                Hide Revoked:
                <input type="checkbox" id="hideRevoked" style = "vertical-align: middle" @Html.Raw(ViewBag.hideRevoked == true ? "checked" : "") />
            </div>
        </div>

        <table width="100%">
            <tbody>
                <tr>
                    <td width="65%" valign="top">
                         
                         <div style="height: 440px; border-style: solid; border-width: 1px; border-color: #DDDDDD"> 
                         <table class="table table-striped">
                              <thead>
                                <tr>
                                    <th>
                                        <a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "IPAddress", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">IP Address</a>
                                    </th>
                                    <th>
                                        <a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "DomainName", (Model.SortDirection == "ASC" ? "DESC" : "ASC" ))">Name</a>
                                    </th>
                                    <th>
                                        <a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "TimerValue1", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Timer1</a>                    
                                    </th>
                                    <th>
                                        <a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "TimerValue2", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Timer2</a>                                        
                                    </th>
                                    <th>
                                        <a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "RevokeStatus", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Revoked</a>                                                                                
                                    </th>
                                    <th>
                                        <a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex, "DateRevoked", (Model.SortDirection == "ASC" ? "DESC" : "ASC"))">Revoked at</a>                                                                                
                                    </th>
                                </tr>
                              </thead>
                              <tbody>
                                @{
                                    foreach (var domain in Model.List)
                                    {
                                        <tr>
                                            <td>
                                                @Ajax.ActionLink(domain.IPAddress, "EditViewDomain", new { id = @domain.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditDomain" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @Ajax.ActionLink(domain.Name, "EditViewDomain", new { id = @domain.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditDomain" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @Ajax.ActionLink(domain.TimerValue1.ToString(), "EditViewDomain", new { id = @domain.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditDomain" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @Ajax.ActionLink(domain.TimerValue2.ToString(), "EditViewDomain", new { id = @domain.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditDomain" }, new { @class = "grid" })
                                            </td>
                                            <td>
                                                @(domain.RevokeStatus ? Html.Raw("<i class=\"icon-check\"></i>") : Html.Raw(""))
                                            </td>
                                            <td>
                                                @Ajax.ActionLink((domain.DateRevoked.HasValue ? domain.DateRevoked.Value.ToString("MM/dd/yyyy") : " "), "EditViewDomain", new { id = @domain.ID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "divEditDomain" }, new { @class = "grid" })
                                            </td>
                                        </tr>
                                    }
                                }
                                    <tr>
                                        <td colspan="5">
                                            <div class="pagination" style="margin: 0">
                                                <ul>
                                                    @{
                                                        if (Model.PageIndex > 1)
                                                        { 
                                                            <li><a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex - 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-left"></i></a></li>
                                                        }

                                                        for (var i = 1; i <= WebApp.Classes.Statics.GetPages(Model.ResultCount); i++)
                                                        {
                                                            if (i == Model.PageIndex)
                                                            {
                                                                <li class="active"><a href="#">@i</a></li>
                                                            }
                                                            else
                                                            {
                                                                <li><a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", i, Model.SortColumn, Model.SortDirection)">@i</a></li>
                                                            }
                                                        }

                                                        if (Model.PageIndex != WebApp.Classes.Statics.GetPages(Model.ResultCount) && Model.ResultCount != 0)
                                                        { 
                                                            <li><a href="@String.Format("DomainManagement?pageIndex={0}&sortColumn={1}&sortDirection={2}", Model.PageIndex + 1, Model.SortColumn, Model.SortDirection)"><i class="icon-arrow-right"></i></a></li>
                                                        }                                    
                                                    }
                                                </ul>
                                            </div>                        
                                        </td>
                                        <td colspan="2" style="text-align: right">
                                            <br />
                                            <h5>Records: @Model.ResultCount</h5>
                                        </td>
                                    </tr>
                                </tbody>                          
                            </table>
                            </div>

                            <br />
                          @{
                                if (new WebApp.Classes.UserRights(ViewBag.Title).FullControl)
                                { 
                                <div class="btn-group">    
                                    @Ajax.ImageActionLink("<i class=\"icon-plus-sign icon-white\"></i> Create New", "CreateDomain", "Domain", null, new AjaxOptions() { UpdateTargetId = "divEditDomain" }, new { @id = "createDomain", @class = "btn btn-inverse" })
                                </div>    
                                }
                            }
                    </td>
                    <td width="50%" valign="top">
                        <div id="divEditDomain">

                        </div>                          
                    </td>
                </tr>
            </tbody>
        </table>

    </fieldset>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


